package com.nacos.consumer.service;

import com.alibaba.csp.sentinel.slots.block.flow.FlowException;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 通过 FallbackFactory 可以获取异常类型
 */
@Component
public class FeginSentinelFallBackFactroy implements FallbackFactory<FeginService> {

    @Override
    public FeginService create(Throwable throwable) {
        return new FeginService(){

            @Override
            public String get() {
                String info ="";
                if (throwable instanceof FlowException) {
                    info="我是被流控";
                }else {

                    info="我是被降级";
                }
                return info;
            }
        };
    }
}
